package cn.itcast.health.commons.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;


public final class JedisUtil {

    public static String setex(JedisPool jedisPool, final String key, final int seconds, final String value){
        Jedis jedis = null;
        try {
            jedis = jedisPool.getResource();
            return jedis.setex(key,seconds,value);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(null != jedis){
                jedis.close();
            }
        }
        return null;
    }

    public static String get(JedisPool jedisPool,String key){
        Jedis jedis = null;
        try {
            jedis = jedisPool.getResource();
            return jedis.get(key);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(null != jedis){
                jedis.close();
            }
        }
        return null;
    }

    public static String set(JedisPool jedisPool,String key,String value){
        Jedis jedis = null;
        try {
            jedis = jedisPool.getResource();
            jedis.set(key,value);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(null != jedis){
                jedis.close();
            }
        }
        return null;
    }


    public static Long del(JedisPool jedisPool,String key){
        Jedis jedis = null;
        try {
            jedis = jedisPool.getResource();
            return jedis.del(key);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(null != jedis){
                jedis.close();
            }
        }
        return null;
    }



}
